package com.goldgov.branchCircle.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goldgov.branchCircle.dao.AttentionDao;
import com.goldgov.branchCircle.service.Attention;
import com.goldgov.branchCircle.service.AttentionQuery;
import com.goldgov.branchCircle.service.AttentionService;
@Service
public class AttentionServiceImpl implements AttentionService{

	@Autowired
	private AttentionDao attentionDao;

	@Override
	public void saveAttention(String orgID,String userID) {
		Attention a=attentionDao.getAttentionByOrgID(orgID,userID);
		if(null!=a) {
			Integer status=a.getStatus();
			if(null!=status && status==1) {
				a.setStatus(2);
			}else {
				a.setStatus(1);//重新添加关注
			}
			attentionDao.updateAttentionStatus(a);//取消关注
		}else {
			Attention aa=new Attention();
			aa.setOrgID(orgID);
			String orgName=attentionDao.getOrgNameByID(orgID);
			aa.setOrgName(orgName);
			aa.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
			aa.setStatus(1);
			aa.setUserID(userID);
			attentionDao.addAttention(aa);
		}
	}

	@Override
	public List<Attention> getAttentionList(AttentionQuery query) {
		return attentionDao.getAttentionList(query);
	}

	@Override
	public List<Attention> getOrgList(AttentionQuery query) {
		return attentionDao.getOrgList(query);
	}

	@Override
	public List<Attention> getXgOrgList(AttentionQuery query) {
		return attentionDao.getXgOrgList(query);
	}

	@Override
	public String getTreePathByID(String orgID) {
		return attentionDao.getTreePathByID(orgID);
	}

	@Override
	public List<Attention> getTjOrgList(AttentionQuery query) {
		return attentionDao.getTjOrgList(query);
	}

	@Override
	public Attention findAttentionOrg(String orgID, String userID) {
		return attentionDao.findAttentionOrg(orgID, userID);
	}

	@Override
	public Integer findAttentionStatus(String orgID, String userID) {
		return attentionDao.findAttentionStatus(orgID, userID);
	}
	
	/**
	 * 查询是否存在此记录
	 * @param orgID
	 * @return
	 */
	@Override
	public Attention getAttentionByOrgID(String orgID,String userID) {
		return attentionDao.getAttentionByOrgID(orgID, userID);
	}

	@Override
	public List<Attention> getAttentionRank(AttentionQuery query) {
		return attentionDao.getAttentionRank(query);
	}
	
	
}
